#include <iostream>
#include <algorithm>
using namespace std;
int func(int *num,int total)
{
	int i,max,maxn,count,n,flag;
	sort(num,num+total);
	n=*num;
	*(num+total)=2147483647;
	count=0;
	max=1;
	for(i=0;i<=total;i++)
	{
		printf("%d\n",flag);
		if((*(num+i))>n)
		{ 
			
			if(count>max)
			{
				max=count;
				maxn=n;
				flag=1;
			}
			else if(count==max)
				flag=0; 
			n=*(num+i);
			count=0;
		}
		else
			count++;
	}
	cout<<flag<<endl;
	if
	(flag)
		return maxn;
	else
		return -1;
}
int main()
{
	int *num=new int[100],count;
	cin>>count;
	for(int i=0;i<=count-1;i++)
		cin>>num[i];
	int ans=func(num,count);
	cout<<ans<<endl;
	delete num;
	return 0;
}
